package com.tinno.chargelauncher.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.tinno.chargelauncher.listener.BatteryCallback;

public class BatteryReceiver extends BroadcastReceiver {
	private static final String TAG = BatteryReceiver.class.getSimpleName();

	private BatteryCallback mCallback;

	public BatteryReceiver(BatteryCallback callback){
		mCallback = callback;
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		int current = intent.getExtras().getInt("level");	//获取当前电量
		int total = intent.getExtras().getInt("scale");		//获取总电量
		int percent = current * 100 / total;

		if (mCallback != null){
			mCallback.getBatteryInfo(total, current, percent);
		}
		Log.i(TAG, "BatteryReceiver: current=" + current + " total=" + total + " percent=" + percent);
	}
}
